<?php

declare(strict_types=1);

namespace app\middleware;

use core\Request;
use Exception;

class AuthMiddleware
{
    public function handle(Request $request, \Closure $next): void
    {
        if (!$request->session('user_id')) {
            http_response_code(401);
            throw new \Exception("Unauthorized");
        }
        $next($request);
    }
}